Repository navigation
fix(pm-stack backup): pmp_links source resolution + both offsite legs (#7096) - #7363
Conversation
…t both offsite legs The pmp_links export added by #5315 still had unresolved review gaps (code#7096): - DATABASE_URL is read from the LAST matching env-file assignment (a later line is what the service loads), with CR, edge whitespace and one matching quote pair trimmed. The old tr deleted every quote/space in the value, mangling paths with spaces. - file: URL paths are percent-decoded and file:/// and file://localhost/ authorities stripped before the existence check. - An unsupported non-file DATABASE_URL (postgres://, libsql://, ...) now fails the run instead of silently archiving a stale local DB; the failure names only the scheme, never the DSN (it may embed credentials). - With no configured source, <PM_PROJECTOR_DIR>/projector.db is used before the ~/.local/state/pm-projector fallback; a relative value resolves under PM_PROJECTOR_DIR. - The with-db scenario now passes only when the stub log records copyto to BOTH R2 and Drive for the same archive, plus new scenarios for last-assignment, quoted/CR/percent-encoded values, remote-DSN rejection, and relative/PM_PROJECTOR_DIR resolution. Refs #7096, #1744
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 54 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f1908fc6b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if [ -n "$PMP_DIR" ] && [ -f "$PMP_DIR/projector.db" ]; then | ||
| PMP_DB="$PMP_DIR/projector.db" |
There was a problem hiding this comment.
Resolve the projector default under its data directory
When DATABASE_URL is absent and PM_PROJECTOR_DIR points to the projector's working directory, this selects the wrong default database. The projector defaults to file:data/projector.db (pm-stack/projector/src/store.ts:13-15), not file:projector.db; the deployed working directory is set in nixos/services/pm-stack/default.nix:115. If an older projector.db exists at the directory root, this new branch exports its stale links and reports a successful backup instead of preserving the active database's links. Resolve the default to data/projector.db and update the new projector-dir fixture accordingly.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in afda12d: the no-DATABASE_URL default under PM_PROJECTOR_DIR now resolves data/projector.db (the projector default file:data/projector.db in pm-stack/projector/src/store.ts, relative to its working directory). A root-level projector.db is never picked. The projector-dir fixture now puts the active DB at data/projector.db and adds a stale root projector.db, asserting neither it nor the state-dir DB is exported.
| //localhost/*) PMP_DB="/${PMP_DB#//localhost/}" ;; | ||
| ///*) PMP_DB="/${PMP_DB#///}" ;; | ||
| esac | ||
| PMP_DB="$(pmp_url_decode "$PMP_DB")" |
There was a problem hiding this comment.
Preserve URI escaping when opening the decoded database path
For a configured URL such as file:/path/projector%3Fprod.db, decoding produces the correct filesystem path for the existence check, but the subsequent SQLite calls interpolate it into file:$PMP_DB?mode=ro again. The decoded ? becomes query syntax, so SQLite opens /path/projector instead of /path/projector?prod.db; encoded # and percent escapes have similar problems. Consequently, these newly supported URLs can fail the entire backup or export a different database. Re-escape the resolved path before constructing the SQLite URI, or pass the decoded filename with SQLite's documented -readonly option (sqlite3 --help: “open the database read-only”).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in afda12d: the export no longer interpolates the decoded path into a file:...?mode=ro URI. All three SQLite calls now use sqlite3 -readonly with the decoded path as a plain filename, so a literal ? or # in the name stays a filename character. New env-encoded-q test case: DATABASE_URL=file:...projector%3Fprod.db exports the real projector?prod.db file; the full pmp-links suite passes.
…DB read-only by path Codex review on PR #7363, two P2 findings: (1) the projector default is file:data/projector.db relative to its working directory (pm-stack/projector/src/store.ts), so the PM_PROJECTOR_DIR fallback now resolves data/projector.db and never a stale root projector.db; the projector-dir fixture now covers the stale-root case. (2) A percent-decoded path containing ? or # broke when re-interpolated into a file:...?mode=ro SQLite URI; the export now opens the decoded path with sqlite3 -readonly instead. New env-encoded-q case covers a literal ? filename. Targeted suites pass: pm-dashboard-backup-pmp-links.test.sh, pm-dashboard-backup-manifest.test.sh.
Fixes #7096 — bounded follow-up to the unresolved review findings on merged PR #5315. Needed for issue #1744 criterion 3 (pmp_links recoverable from the archive).
What changed (
nixos/home/pm-dashboard-backup.sh)DATABASE_URLis taken from the last matching env-file line (optionallyexport-prefixed, spaces around=), because a later assignment is what the service actually loads.tr -ddeleted every quote and space anywhere in the value and mangled paths with spaces.file:URLs decoded. Percent escapes are decoded andfile:////file://localhost/authorities collapsed before the existence check, sofile:/a%20b/projector.dbfinds the real file.fileDATABASE_URL (postgres://,libsql://, ...) fails the run with apmp_linkserror naming only the scheme — never the DSN, which may embed credentials. Archiving a stale local DB instead would make the backup evidence claim a source it never read.PM_PROJECTOR_DIRresolution. With no configured source,<PM_PROJECTOR_DIR>/projector.dbis used before the~/.local/state/pm-projectorfallback; a relative value resolves underPM_PROJECTOR_DIR. Bare local paths in DATABASE_URL are now honoured instead of being ignored.Tests (
nixos/home/pm-dashboard-backup-pmp-links.test.sh)with-dbpasses only when the stub log recordscopytoto both R2 and Drive for the same archive (previously any single upload passed).env-last(stale first assignment must not win),env-quoted(quoted, CR-terminated, percent-encoded path containing a space),env-remote(explicit failure, nothing uploaded, cursor unchanged, DSN not leaked),env-relative+projector-dir(relative/default resolution underPM_PROJECTOR_DIRbefore the state fallback).PM_PROJECTOR_*are cleared per scenario so ambient values cannot pick the source.Verification
bash nixos/home/pm-dashboard-backup-pmp-links.test.sh— all passed (21 checks)bash nixos/home/pm-dashboard-backup-manifest.test.sh— all passedcopy,date,prune,record, basepm-dashboard-backup.test.shNo export re-implementation, no data/service migration; scope is only source resolution and the offsite-leg assertion.
Queue task
12738(lane 7b47536b, worker repo-worker-code).Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.